<template>
    <div class="order-main allow">
        <section class="order-main-header">
             <mt-header title="亏损补贴">
            <mt-button  icon="back" slot="left" @click="handleClose()"></mt-button>
                 <mt-button  slot="right" @click="handleNotice()"><img src="../../assets/action/not.png"></mt-button>
            </mt-header>
        </section>
        <div class="container allow">
             <div class="page-tab-container" >
                 <div class="cash">
                     <div class="list">
                         <span>{{subsidyList.coinName}}</span>
                         <div class="sure">
                             <span>亏损金额<p>{{checkCash.lossMoney?checkCash.lossMoney:'0'}} &nbsp;USDT</p></span>
                            <span>已兑付总金额<p>{{subsidyList.exchangeMoney?subsidyList.exchangeMoney:'0'}} &nbsp;USDT</p></span>
                            <button @click="exchangeSub()">兑付</button>
                         </div>
                     </div>
                 </div>
                  <span class="relocy">兑付记录</span>
                <div v-if="recordList.length>0">
                        <div class="order-table" v-for="(orderData, i) in recordList" v-bind:key="i" >
                            <div class="order-header">
                                <div class="flex-between black">
                                    <span>兑付ID：{{orderData.id}}</span>
                                     <p>{{ timestampToTime(new Date(orderData.createTime))}}</p>
                                </div>
                            </div>
                             <div class="order-content flex-between">
                                <div class="left">
                                    <p>亏损(USDT)</p><p>{{orderData.lossMoney?orderData.lossMoney:"0"}}</p>
                                </div>
                                 <div class="left">
                                    <p>兑付({{subsidyList.coinName}})</p><p>{{orderData.allowanceNum}} </p>
                                </div>
                                 <div class="left">
                                    <p>单价(USDT)</p><p>{{orderData.allowancePrice}}</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div v-if="recordList.length==0" class="data-img">
                        <img src="../../assets/report.png">
                        <p style=" margin-top: 100px;">暂无兑付记录</p>
                    </div>
            </div>
        </div>
        <section class="el-toast" v-if="cationModal">
              <div class="el-modal">
                   <div class="modal-top">
                       <div class="modal-top-error" @click="handleNoticeCancel()"><img src="../../assets/action/error.png"></div>
                       <div class="modal-header">
                            <span>亏损补贴</span>
                        </div>
                        <!-- <div class="modal-header-content">
                            <span>任意时间皆可参与锁仓。按锁仓开始日期统计，在本季度内锁仓账户均允许参加该季度信仰锁仓抽奖。抽奖是否成功均发送短信给用户。</span>
                        </div> -->
                   </div>
                    <div class="modal-bottom">
                       <div class="modal-bottom-content">
                          <span>1、 当用户共识买卖亏损超过10%平台将给予补贴亏损部分105%等值BZB。</span>
                             <span>2、 用户点击申请时，按申请时最新价补贴等值BZB至币币账户中。</span>
                        </div>
                   </div>
              </div>
        </section>
    </div>
</template>
<script>
import { Toast } from 'mint-ui';
import { MessageBox } from 'mint-ui';
export default {
    name:'myOrder',
    data(){
         return {
             subsidyList:{coinName:'BZB'},
             recordList:[],
             fid:'',
             sessionData:'',
             checkCash:'',
             checkCashState:{code:''},
             rewards:'',
             symbol:'',
             cationModal:false,
         }
    },
    mounted() {
            this.$http.post('v1/session?'+ new Date().getTime(),).then((res)=>{
            this.sessionData=res.data.data;
            if(res.data.code==1){
                this.$router.push("/login");
            }
            this.getOtcList();
        })
    },
    methods: {
           getOtcList(){this.$http.post('/v2/market/allcoins',).then((res)=>{
                let tickers = res.data;
                 let coinGroup = {}
                    let param = location.hash.match(new RegExp(".*" + 'symbol' + "=([^\&]*)(\&?)", "i"));
                    let symbol = param && !isNaN(param[1]) ? param[1] : 0;
                    let current = null;
                    for (let i = 0; i < tickers.length; i++) {
                        let ticker = tickers[i]
                        if(ticker.report){
                            current = ticker
                        }
                    }
                    this.symbol=current;
                     this.getCheckCash(current);
                     this.getCheckCashList(current);
             })
           },
         exchangeSub(){
         if(this.checkCashState.code==10006){
             Toast(this.checkCashState.msg);
             return
         }
             let self=this;
                MessageBox.confirm('您的亏损'+this.checkCash.lossMoney+'USDT'+'，兑付105%等值'+this.symbol.fShortName+'预计'+(this.checkCash.subsidyNumber)+'个，是否兑付').then(action => {
                this.$http.post('v2/subsidy/onCash',{userId: this.sessionData.id,fViFId: this.symbol.coinId}).then((res) => {
           let data=res.data;
            if (data.code == 0) {
                Toast("兑换成功");
                self.getCheckCashList(this.symbol);
            }else{
                   Toast(data.msg);
            }
      })
        });
    },
         getCheckCash(current){
             let self=this;
       this.$http.post('v2/subsidy/checkCash',{userId: this.sessionData.id,fViFId:current.coinId}).then((res) => {
           let data=res.data;
            if (data.code == 0) {
                  this.checkCash=data.data;
            }else if(data.code=10006){
                this.checkCashState=data;
            }
      })
    },
      getCheckCashList(current){
           this.recordList=[];
       this.$http.post('v2/subsidy/list',{userId: this.sessionData.id,fViFId:current.coinId}).then((res) => {
           let data=res.data;
            if (data.code == 0) {
                  this.subsidyList=data.data;
                  this.recordList=data.data.recordList;
                  if(this.recordList==null){
                      this.recordList=[];
                  }
            }
      })
    },
    handleNoticeCancel(){
          this.cationModal=false;
    },
    handleNotice(){
            this.cationModal=true;
        },
            handleClose(){
                this.$router.go(-1);
            },
                  timestampToTime (cjsj) {
        var date = new Date(cjsj) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-'
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
        var D = date.getDate() + ' '
        var h = date.getHours() + ':'
        var m = date.getMinutes() + ':'
        var s = date.getSeconds()
        return Y+M+D+h+m+s
        console.log(timestampToTime (1533293827000))
    },
    },
}
</script>
<style lang='less' scoped>

.allow {
    .order-table{
    padding: 20px 30px 20px 30px;
    background: #222240;
    position: relative;
    margin-bottom: 20px;
}
    .order-main .sell{
width: 50%;
height: 100px;
line-height: 100px;
text-align: center;
.order-main-header{
    display: flex;
    flex-direction: row;
    height: 100px;
}
}
}
.allow .cash{
    height:224px;
background:rgba(34,34,64,1);
} 
.allow .order-content{
    padding-top: 20px;
    color: #E0E0F9
}
.allow .cash .list{
    position: relative;
    padding: 30px;
    }
    .allow .cash .list >span{
    font-size:36px;
    color:rgba(255,255,255,1);
    margin-bottom: 30px;
    margin-top: 20px;
    }
    .allow .cash .list .sure{
      display: flex;
    flex-direction: row;
    color: #8686C0;
    line-height:50px;
    font-size:28px;
    }
    .allow .cash .list .sure >span:nth-child(1){
     width: 40%;
    }
    .allow .cash .list .sure >span:nth-child(2){
     width: 50%;
    }
    .relocy{
        font-weight:500;
color:rgba(224,224,249,1);
line-height:40px;
margin-left: 30px;
margin-top: 30px;
margin-bottom: 30px;
    }
    .allow .cash .list .sure button{
        height:60px;
background:rgba(82,152,241,1);
border-radius:8px;
width:140px;
 font-size:28px;
 color:rgba(255,255,255,1);
    }

.allow .order-main-header header{
    width: 100%;
}
.page-tab-container{
    height: 100%;
}
.data-img{
        min-height: 850px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column
}
.data-img img{
     width: 450px;
    height: 100%;
}
.order-content .left:nth-child(1){
    width: 33.3%;
}
.order-content .left:nth-child(2){
    width: 33.3%;
    text-align: center;
}
.order-content .left:nth-child(3){
    width: 33.3%;
     text-align: center;
}
.order-content .left{
    color: #E0E0F9;
    display: flex;
    height: 144px;
    flex-direction: column;
}
.order-content .left p{
   line-height: 70px;
   height: 70px;
}
.order-header{
    height: 80px;
    line-height: 80px;
    border-bottom:1px solid #161736
}
.rect{
    height:10px;
    background:rgba(244,244,244,1);
}

.order-main .left p{
    font-size: 24px;
}
.order-main .left p:nth-child(1){
    color: #8686C0;
}
.nav{
    display: flex;
    flex-direction: row;
}
.black{
    color: #E0E0F9;
    font-weight:300;
    font-size:30px;
}
.flex-center{
    display: flex;
   align-self: center;
}
.flex-between{
      display: flex;
        justify-content: space-between;
    }
    .end{
        background: #8c9fad
    }
    .start{
          background:#F2635B;
    }
    .submit {
    width: 120px;
    height: 68px;
    font-size: 28px;
    line-height: 68px;
    font-weight: 700;
    color: #fff;
    border-radius:5px;
}

.tabs .img{
    width: 40px;
    height: 40px;
    position: relative;
    right: 20px;
    top:30px;
}
.order-main .buy{
width: 50%;
height: 100px;
line-height: 100px;
text-align: center;
}
.order-main .buy span{
text-align: center;
width: 50%;
line-height: 100px;
height: 90%;
}
.flex-content{
      display: -ms-flexbox;
    display: flex;
    justify-content: center;
}
.order-main .sell span{
width: 50%;
height: 90%;
line-height: 100px;
}
.tab-content{
    width: 80%;
    margin: 0 auto;
    font-size: 32px;
    font-weight:500;
}
.order-main .tab{
display: flex;
background:rgba(255,255,255,1);
height: 100px;
border-bottom:1px solid #161736
}
.order-main .active{
color: #3381FF;
}
.allow .mint-header{
    height: 100px;
    font-size: 32px;
    background-color: rgba(34,34,64,1);
    color: #E0E0F9;
    margin-bottom: 10px;
}
.data-img p{
color: #fff;
}
.el-toast {
    .el-modal{
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100%;
        flex-direction: column;
        margin-top: -25%
    }
    .modal-top{
        width:638px;
    height:100px;
    line-height: 100px;
    background:rgba(34,34,64,1);
    border-radius:4px 4px 0px 0px;
    color: #fff;
    display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        .modal-header {
            font-size:36px;
            height: 60px;
            position: relative;
            top:-70px;
        }
        .modal-header-content{
            text-align: left;
            line-height: 40px;
            padding-left: 30px;
        }
    }
    .modal-bottom{
         .modal-bottom-content{
             span{
                 height: 50%;
                 line-height: 1.5
             }
              padding-left: 30px;
              height: 100%;
              text-align: left;
              p{
                  height: 70px;
                  line-height: 60px;
                   font-size:28px;
                 color: rgba(82, 152, 241, 1);
              }
             span :nth-child(1){
                 line-height: 60px;
                height: 60px;
             }
         }
        width:638px;
    height:240px;
     background:rgba(34,34,64,1);
     color: #fff;
    border-radius:4px 4px 0px 0px;
    position: relative;
    top:-2px;
    }
    .flex-between{
      display: flex;
        justify-content:start
    }
    height: 100%;
    margin-top: 100px;
    position: fixed;
    background: rgba(22, 23, 54, 1);
    width: 100%;
    text-align: center;
    bottom: 0;
    top: 0%;
    z-index: 10000;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transition: -webkit-transform 0.3s ease-out;
    transition: -webkit-transform 0.3s ease-out;
    transition: transform 0.3s ease-out;
    transition: transform 0.3s ease-out, -webkit-transform 0.3s ease-out;
}
.toast-modal{
    background: #161736;
}
.modal-top-error{
    position: relative;
    left: 280px;
    float: right;
    top: 10px
}
</style>